<template>
  <div class="inventory-list-container">
    <CPageTable @register="registerPage" v-model:searchForm="searchForm">
      <template #headerRightButton>
        <el-button
          type="primary"
          @click="handleDownloadReport"
          v-btnPermission="'ECI_REPORT_DOWNLOAD'"
        >
          <CIcon type="c-xian-xiazai" class="g-mr4"></CIcon>下载报告</el-button
        >
        <el-button
          type="primary"
          @click="handleDownload"
          v-btnPermission="'ECI_INVENTORY_DOWNLOAD'"
        >
          <CIcon type="c-xian-xiazai" class="g-mr4"></CIcon>下载清册</el-button
        >
      </template>
      <template #table>
        <EmissionSummary
          :standard="searchForm.standard"
          v-if="searchForm.type == 'EmissionSummary'"
        ></EmissionSummary>
        <SourceIdentification
          :standard="searchForm.standard"
          v-else-if="searchForm.type == 'SourceIdentification'"
        ></SourceIdentification>
        <DataCollection
          :standard="searchForm.standard"
          v-else-if="searchForm.type == 'DataCollection'"
        ></DataCollection>
        <FactorSelection
          :standard="searchForm.standard"
          v-else-if="searchForm.type == 'FactorSelection'"
        ></FactorSelection>
        <EmissionCalculation
          :standard="searchForm.standard"
          v-else-if="searchForm.type == 'EmissionCalculation'"
        ></EmissionCalculation>
        <div style="background: #ffffff; height: 48px; border-radius: 0px 0px 3px 3px"></div>
      </template>
    </CPageTable>
  </div>
</template>
<script lang="ts">
export default {
  name: 'CarbonDetail'
};
</script>
<script lang="ts" setup>
import { CPageTable, useCPageTable } from '@/components/CPageTable';
import DataCollection from './components/DataCollection/index.vue';
import EmissionCalculation from './components/EmissionCalculation/index.vue';
import EmissionSummary from './components/EmissionSummary/index.vue';
import FactorSelection from './components/FactorSelection/index.vue';
import SourceIdentification from './components/SourceIdentification/index.vue';
import { useInventory } from './useInventory';
import { exportInventory } from '@/apis/eci/carbonManagement/dataList';
import { useExport } from '@/hooks/useExport';
import { useRoute } from 'vue-router';
import { exportReport } from '@/apis/eci/carbonManagement/dataList';
import type { ExportReportParams } from '@/apis/eci/carbonManagement/model/dataListModel';

const { searchForm, options } = useInventory();
const [registerPage] = useCPageTable(options);
const { handleExportFile } = useExport();
const route = useRoute();
const taskNo = route.query.taskNo as string;
const handleDownload = () => {
  handleExportFile(exportInventory, {
    taskNo,
    standard: searchForm.standard
  });
};
const handleDownloadReport = () => {
  handleExportFile<ExportReportParams>(exportReport, {
    inventoryTaskNoList: [taskNo],
    standard: searchForm.standard
  });
};
</script>

<style lang="scss" scoped>
.inventory-list-container {
  // 表格边框颜色
  --el-border-color-lighter: #e4e7ed;
  .g-tag {
    &.el-tag--success {
      color: #37b17d;
      background-color: rgba(55, 177, 125, 0.06);
      border-color: #37b17d;
    }
  }
}
</style>
